package com.kczd.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.kczd.activity.OrderFinishedDetailsActivity;
import com.kczd.adapter.LocationAdapter;
import com.kczd.client.R;
import com.kczd.entity.Location;

import java.util.ArrayList;
import java.util.List;

/**
 * zhangy
 * Created by Administrator on 2017/3/5 0005.
 */

public class OrderFinishedFragment extends Fragment{
    private View view;
    private ListView lv_caListView;
    public static List<Location> orderFinishedlsit = new ArrayList<Location>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        view=inflater.inflate(R.layout.fragment_order_finished, null);
        setview();
        return view;
    }
    private void setview() {
        //将数据显示在listview上
        //1.获得ListView对象
        lv_caListView=(ListView) view.findViewById(R.id.lv_cancel);
        //2.构建Adapter对象
        LocationAdapter adapter=new LocationAdapter(getActivity(), R.layout.list_item_order_item, orderFinishedlsit);
        lv_caListView.setAdapter(adapter);

        lv_caListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                //新建一个显式意图，第一个参数为当前Activity类对象，第二个参数为你要打开的Activity类
                Intent intent =new Intent(getActivity(), OrderFinishedDetailsActivity.class);

                //用Bundle携带数据
                Bundle bundle=new Bundle();
                //传递参数
                bundle.putInt("position", position);
                intent.putExtras(bundle);

                startActivity(intent);
            }
        });
        //添加长按点击
        lv_caListView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {

            @Override
            public void onCreateContextMenu(ContextMenu menu, View v,
                                            ContextMenu.ContextMenuInfo menuInfo) {
                menu.add(0, 0, 0, "删除");
            }
        });
    }

    //长按菜单响应函数
    @Override
    public boolean onContextItemSelected(MenuItem item) {
        //"点击了长按菜单里面的第"+item.getItemId()+"个项目"
        return super.onContextItemSelected(item);
    }

}

